package com.xiaouyudeguang.common.utils;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;

public class CopyUtils {

	public static <T> T getInstance(Class<T> targetCls) {
		try {
			return targetCls.newInstance();
		} catch (InstantiationException | IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}


	public static <T> T copy(Object source, T target) throws BeansException {
		if (source != null) {
			BeanUtils.copyProperties(source, target);
		}
		return target;
	}

	public static <T> T copy(Object source, Class<T> targetCls) throws BeansException {
		return copy(source, getInstance(targetCls));
	}
}